/**
 * Created by lbs on 2017/3/20.
 */

app.factory('postData', ['$http', '$q', function ($http, $q,token) {
    return {
        post: function (url, data) {
            var deferred = $q.defer();
            console.log(localStorage['token']);
            $http({
                method: 'POST', url: url, data: data,
                transformRequest: function (obj) {
                    var str = [];
                    for (var p in obj) {
                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                    }
                    return str.join("&");
                },
                headers: {'Content-Type': 'application/x-www-form-urlencoded','authorization':token},
            }).success(function (data, status, headers, config) {
                deferred.resolve(data);
            }).error(function (data, status, headers, config) {
                deferred.reject(data);
            });
            return deferred.promise;
        }
    };
}])